﻿using KouDai.Core.BLL;
using KouDai.Core.Engine;
using KouDai.Core.Models;
using KouDai.Core.Service.Navigation;
using Modern.MvvM;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Windows.Input;

namespace KouDai.Core.ViewModel
{
    public class MainViewModel : NavigateViewModel
    {
        #region Fields
        private readonly INavigateService _navigateService;
        private ICommand _goToDetailCommand;
        private ObservableCollection<HoneyEntity> _items = new ObservableCollection<HoneyEntity>();
        private HoneyWallBLL _kouDaiService;

        #endregion

        #region Constructor
        public MainViewModel(INavigateService navigateService) : base(navigateService)
        {
            Debug.WriteLine("Constructor--->");
            _navigateService = navigateService;
            _kouDaiService = new HoneyWallBLL();


            Items.Add(new HoneyEntity
            {
                ID = "taobao16428206747",
                ImageUrlForIphone = "http://img.geilicdn.com/taobao16428206747_146x219.jpg",
                ImgRatio = "1.50",
                Name = "『Some Time』淑女范~领部褶皱荷叶边边棉服~预定",
                Price = "￥118"
            });
            Items.Add(new HoneyEntity
            {
                ID = "taobao16428206747",
                ImageUrlForIphone = "http://img.geilicdn.com/taobao16428206747_146x219.jpg",
                ImgRatio = "1.50",
                Name = "『Some Time』淑女范~领部褶皱荷叶边边棉服~预定",
                Price = "￥118"
            });
            Items.Add(new HoneyEntity
            {
                ID = "taobao16428206747",
                ImageUrlForIphone = "http://img.geilicdn.com/taobao16428206747_146x219.jpg",
                ImgRatio = "1.50",
                Name = "『Some Time』淑女范~领部褶皱荷叶边边棉服~预定",
                Price = "￥118"
            });
            Items.Add(new HoneyEntity
            {
                ID = "taobao16428206747",
                ImageUrlForIphone = "http://img.geilicdn.com/taobao16428206747_146x219.jpg",
                ImgRatio = "1.50",
                Name = "『Some Time』淑女范~领部褶皱荷叶边边棉服~预定",
                Price = "￥118"
            });
            Items.Add(new HoneyEntity
            {
                ID = "taobao16428206747",
                ImageUrlForIphone = "http://img.geilicdn.com/taobao16428206747_146x219.jpg",
                ImgRatio = "1.50",
                Name = "『Some Time』淑女范~领部褶皱荷叶边边棉服~预定",
                Price = "￥118"
            });

            Items.Add(new HoneyEntity
            {
                ID = "taobao16428206747",
                ImageUrlForIphone = "http://img.geilicdn.com/taobao16428206747_146x219.jpg",
                ImgRatio = "1.50",
                Name = "『Some Time』淑女范~领部褶皱荷叶边边棉服~预定",
                Price = "￥118"
            });
            Items.Add(new HoneyEntity
            {
                ID = "taobao16428206747",
                ImageUrlForIphone = "http://img.geilicdn.com/taobao16428206747_146x219.jpg",
                ImgRatio = "1.50",
                Name = "『Some Time』淑女范~领部褶皱荷叶边边棉服~预定",
                Price = "￥118"
            });
            Items.Add(new HoneyEntity
            {
                ID = "taobao16428206747",
                ImageUrlForIphone = "http://img.geilicdn.com/taobao16428206747_146x219.jpg",
                ImgRatio = "1.50",
                Name = "『Some Time』淑女范~领部褶皱荷叶边边棉服~预定",
                Price = "￥118"
            });

        }
        #endregion

        ~MainViewModel()
        {
            Debug.WriteLine("Clear-->");
        }

        #region Command
        public ICommand GoToDetailCommand 
        {
            get { return _goToDetailCommand ?? (_goToDetailCommand = new RelayCommand(GoToDetailExecute)); }
        }
        #endregion

        #region Properties

        public ObservableCollection<HoneyEntity> Items
        {
            get { return _items; }
            set { base.SetProperty(ref _items, value, () => this.Items); }
        }
        #endregion

        #region Method

        public async Task GetItems()
        {
            BackData backData = await _kouDaiService.GetWallData("Combine_Default", 0);

            if (backData.IsSuccess)
            {
                List<HoneyEntity> honeyItems = backData.ResposeData as List<HoneyEntity>;
                Debug.WriteLine(honeyItems.Count);
                honeyItems.ToObservableCollection(this.Items);
            }
        }

        private void GoToDetailExecute()
        {
            _navigateService.NavigateTo<ItemDetailViewModel>("Parameter");
        }

        #endregion

    }
}